package rai.portlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import rai.dao.CourseInfoDAO;
import rai.dao.EditExperienceDAO;
import rai.dao.ProjectInfoDAO;
import rai.dto.CompanyDTO;
import rai.dto.CourseDTO;
import rai.dto.DepartmentDTO;
import rai.dto.ProjectEmpInfoDTO;
import rai.dto.TakenCourseDTO;


/**
 * Servlet implementation class AddActionServlet
 * @author Vu
 */
public class AddActionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/** log property. */
    private static Logger log = Logger.getLogger("SearchInfoPortlet");
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddActionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    String compID = request.getParameter("lstComp");
        String Name = request.getParameter("name");
        EditExperienceDAO dao = new EditExperienceDAO();
        ServletOutputStream a = response.getOutputStream();
        
        if (compID != null && Name != null) {
            // request.getSession().setAttribute("lstCompID",Compid);
            //request.setAttribute("compAdd", "1278/8");
            log.info("Start DepartmentListServlet" + compID);

            List<DepartmentDTO> list_dep = dao.getDep(compID);
            log.info("Start DepartmentListServlet" + compID);
            a.print("<select name=\"" + Name
                        + "\">");
            log.info("Start DepartmentListServlet" + compID);
            for (int i = 0; i < list_dep.size(); i++) {
                DepartmentDTO exp = new DepartmentDTO();
                exp = list_dep.get(i);
                a.println("<option value=" + exp.getId() + ">" + exp.getSname()
                        + "</option>");

            }
            a.println("</select>");
            log.info("Start DepartmentListServlet" + compID);
            CompanyDTO expDTO = dao.getCompInfo(Integer.parseInt(compID));
            log.info("Start DepartmentListServlet" + compID);
            a.println("######");
            a.println(expDTO.getCompAdd());
            a.println("######");
            a.println(expDTO.getCompPhone());
            a.flush();
            a.close();
            log.info("Stop DepartmentListServlet");
        }
        
        String prjID = request.getParameter("lstPrj");
        if (prjID != null) {
            ProjectInfoDAO prjDao = new ProjectInfoDAO();
            ProjectEmpInfoDTO prjDTO = prjDao.getPrjInfo(Integer.parseInt(prjID), 0);
            
            a.println(prjDTO.getDes());
            a.println("######");
            a.println(prjDTO.getCompany());
            a.println("######");
            a.println(prjDTO.getDept());
            a.println("######");
            a.println(prjDTO.getStart());
            a.println("######");
            a.println(prjDTO.getEnd());
            a.println("######");
            a.println(prjDTO.getSize());
            a.flush();
            a.close();
        }
        
        String courseID = request.getParameter("lstCourse");
        if (courseID != null) {
            CourseInfoDAO courseDAO = new CourseInfoDAO();
            TakenCourseDTO courseDTO = courseDAO.getCourseInfo(Integer.parseInt(courseID), 0);
            
            a.println(courseDTO.getDes());
            a.println("######");
            a.println(courseDTO.getCompany());
            a.println("######");
            a.println(courseDTO.getDept());
            a.println("######");
            a.println(courseDTO.getDate());
            a.println("######");
            a.println(courseDTO.getPeriod());
            
            a.flush();
            a.close();
        }
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
